<template>
    <section>
<div v-show="masterVisable">
                <sy-baselist
                        ref="project"
                        title="项目"
                        fixOperate
                        :autoSearch="true"
                        @beforeAdd="beforeAdd"
                        editVue="./customer/Project_Edit.vue"
                        listUrl="server/customer/Project.ashx?cmd=GetList"
                        deleteUrl="server/customer/Project.ashx?cmd=Delete"
                >
                    <el-table-column prop="FName" label="项目名称" width="180" >
                    </el-table-column>
                    <el-table-column prop="FContent" label="项目建设内容" width="400" >s
                    </el-table-column>
                    <el-table-column prop="FDeadline" label="建设期限" width="110" >
                    </el-table-column>
                    <el-table-column prop="FAmount" label="投资额(万元)" width="80" >
                    </el-table-column>
                    <el-table-column prop="FFixAmount" label="固定投资额(万元)" width="100">
                    </el-table-column>
                    <el-table-column prop="FIsHasContract" label="是否已签合同" width="80" >
                    </el-table-column>
                    <el-table-column prop="FSource" label="项目来源" width="120" >
                    </el-table-column>
                    <el-table-column prop="FStatus" label="项目进度" width="150" >
                    </el-table-column>
                    <el-table-column prop="Collections" label="材料收集情况" width="300" >
                        <template scope="scope">
                            <el-popover trigger="hover" placement="top">
                                <div v-html="scope.row.Collections"> </div>
                                <div slot="reference" v-html="min(scope.row.Collections)">
                                </div>
                            </el-popover>
                        </template>
                    </el-table-column>
                    <el-table-column prop="FNote"  header-align="center" label="备注" width="250" >
                    </el-table-column>
                    <template  scope="props" slot="extendbtn">
                        <div style="padding: 2px">  </div>
                        <el-button size="small"  style="margin-left: 0px;" @click="viewContract(props.row)">合同</el-button>
                        <div style="padding: 2px">  </div>
                        <el-button size="small"  style="margin-left: 0px;" @click="collection(props.row)">材料收集</el-button>
                        <div style="padding: 2px">  </div>
                        <el-button size="small"  style="margin-left: 0px;" @click="viewTrace(props.row)">项目跟踪</el-button>
                        <div style="padding: 2px">  </div>
                    </template>
                </sy-baselist>
 </div>

<div v-show="detailVisable">
    <sy-baselist
                        ref="projectTrace"
                        title="项目跟踪"
                        @beforeAdd="beforeAddTrace"
                        :autoSearch="false"
                        fixWhere="FType=0"
                        editVue="./customer/ProjectTrace_Edit.vue"
                        listUrl="server/customer/ProjectTrace.ashx?cmd=GetList"
                        deleteUrl="server/customer/ProjectTrace.ashx?cmd=Delete"
                >
                    <el-table-column prop="FCreateDate" label="跟进时间" :formatter="formatDate" width="110" >
                    </el-table-column>
                    <el-table-column prop="FLinkMan" label="客方联系人"  width="110" >
                    </el-table-column>
                    <el-table-column prop="FLinkPhone" label="客方联系电话"  width="150" >
                    </el-table-column>
                    <!--<el-table-column prop="FTitle" label="跟进主题" width="120" >-->
                    <!--</el-table-column>-->
                    <el-table-column prop="FContent" label="跟进内容" width="450" >
                    </el-table-column>
                    <el-table-column prop="FTalkTime" label="通话时长(分钟)"  width="150" >
                    </el-table-column>
                    <el-table-column prop="FRealName" label="跟进人"  width="160" >
                    </el-table-column>
                    <el-table-column prop="FMyPhone"  header-align="center" label="拨出电话号码"  width="130" >
                    </el-table-column>
                    <el-table-column prop="FToDate" label="再跟进时间" :formatter="formatDate" width="110">
                    </el-table-column>
                    <template slot="extendbtnTop">
                        <!--<el-button :loading="loadAddYx" @click="addYXCustomer" type="primary" size="small">当日新增意向客户</el-button>-->
                        <!--<el-button :loading="loadSendContract" @click="sendContract" type="primary" size="small">当日发合同给客户</el-button>-->
                        <!--<el-button :loading="loadSignBill" @click="signBill" type="primary" size="small">当日和客户签单</el-button>-->
                        <el-button @click="back" type="success" size="small" icon="caret-left">返回项目列表</el-button>
                    </template>
                </sy-baselist>
</div>

        <div v-show="contractVisable">
            <el-tag style="margin: 0px 0 10px 20px"  type="gray">合同详情</el-tag>
            <el-button style="margin: 0px 0 10px 20px" @click="back" type="success" size="small" icon="caret-left">返回项目列表</el-button>
            <ProjectContract ref="projectContract"></ProjectContract>
        </div>

        <ProjectCollection_Edit @onSaveSuc="onPCSaveSuc" ref="projectCollection">
        </ProjectCollection_Edit>

    </section>
</template>

<script>
    import mixin from '../../common/mixin'
    import util from '../../common/util'
    import ProjectContract from "./ProjectContract_Detail.vue"
    import ProjectCollection_Edit from "./ProjectCollection_Edit.vue"
    export default {
        mixins: [mixin],
        data(){
            return {
                contractVisable:false,
                detailVisable:false,
                masterVisable:true,
                FProjectID:0,
                custID:0,
                loadAddYx:false,
                loadSendContract:false,
                loadSignBill:false
            }
        },
        components:{
            ProjectContract:ProjectContract,
            ProjectCollection_Edit:ProjectCollection_Edit
        },
        methods:{
            _init(custID){
                this.back()
                this.custID = custID
                this.$refs.project._search("1=1","FCustID="+custID)
            },
            //////////////////////////////////////////////////////////
            addYXCustomer(){
                let param = {
                    custID:this.custID,
                    projectID:this.FProjectID
                }
                util.post("server/customer/ProjectTrace.ashx?cmd=AddYXCustomer",param,this.loadFn("loadAddYx"),result=> {
                    util.msgSuc("操作成功")
                    this.$refs.projectTrace._refrash()
                })
            },
            sendContract(){
                let param = {
                    custID:this.custID,
                    projectID:this.FProjectID
                }
                util.post("server/customer/ProjectTrace.ashx?cmd=SendContract",param,this.loadFn("loadSendContract"),result=> {
                    util.msgSuc("操作成功")
                    this.$refs.projectTrace._refrash()
                })
            },
            signBill(){
                let param = {
                    custID:this.custID,
                    projectID:this.FProjectID
                }
                util.post("server/customer/ProjectTrace.ashx?cmd=SignBill",param,this.loadFn("loadSignBill"),result=> {
                    util.msgSuc("操作成功")
                    this.$refs.projectTrace._refrash()
                })
            },
            min(text){
                let arr = text.split("<br>")
                if(arr.length>=6){
                    return arr.slice(0,6).join("<br>") + "......"
                }
                return text
            },
            back(){
                this.contractVisable = false
                this.detailVisable = false
                this.masterVisable = true
            },
            beforeAddTrace(row,r){
                if(this.FProjectID==0) {
                    return r.error = "请先选择项目";
                }
                row.FCustID = this.custID
                row.FProjectID = this.FProjectID
            },
            beforeAdd(row,r){
                if(!this.custID){
                    return r.error = "请选择客户";
                }
                row.FCustID = this.custID
            },
            beforeAddBankroll(row,r){
                if(this.FProjectID==0) {
                    return r.error = "请先选择项目";
                }
                row.FCustID = this.custID
                row.FProjectID = this.FProjectID
            },
            viewContract(row){
                this.contractVisable = true
                this.masterVisable = false
                this.FProjectID = row.FID
                this.$refs.projectContract._init(row.FID)
            },
            viewBankroll(row){
                this.masterVisable = false
                this.FProjectID = row.FID
                this.$refs.projectBankroll._search("FProjectID=" + row.FID)
            },
            viewTrace(row){
                this.detailVisable = true
                this.masterVisable = false
                this.xyCustomerRow = null
                this.sendContractRow = null
                this.signBillRow = null
                this.FProjectID = row.FID
                this.$refs.projectTrace._search("FProjectID=" + row.FID)
                util.get("server/customer/ProjectTrace.ashx?cmd=GetTraceAddtion",{projectID:row.FID},null,result=> {
                        this.xyCustomerRow = util.date.formatObj(result.xyCustomer, "yyyy-MM-dd")
                        this.sendContractRow = util.date.formatObj(result.sendContract, "yyyy-MM-dd")
                        this.signBillRow = util.date.formatObj(result.signBill, "yyyy-MM-dd")
                })
            },
            getCreateDate(record){
                if(record){
                    return record.FCreateDate
                }
                return ""
            },
            collection(row){
                this.$refs.projectCollection._openEdit(row)
            },
            onPCSaveSuc(){
                this.$refs.project._refrash()
            }
        }
    }
</script>